package com.gxa.community.admin.controller;

import com.gxa.community.admin.service.OperateTicketService;
import com.gxa.community.core.pojo.vo.TicketsAddVo;
import com.gxa.community.core.utils.CodingUtils;
import com.gxa.community.core.utils.R;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RequestMapping("/ticket")
@RestController
public class TicketController {
    @Autowired
    private OperateTicketService operateTicketService;

    @GetMapping("/tickets")
    public R getTickets(@NotNull int page,@NotNull int size){
        R r = operateTicketService.selectAll(page,size);
        return r;
    }


    @GetMapping("/preaddticket")
    public R preAddTicket(){
        String s = CodingUtils.RandomNum();
        return R.ok().put("data",s);
    }


    @PostMapping("/addtickets")
    public R addTickes(@RequestBody TicketsAddVo ticketsAddVo){
        R r = operateTicketService.addTicket(ticketsAddVo);
        return r;
    }


    @DeleteMapping("/deltickets")
    public R delTickes(@NotNull String ticketNo){
        R r = operateTicketService.delTicket(ticketNo);
        return r;
    }


    @GetMapping("/preedittickets")
    public R preEdit(@NotNull String ticketNo){
        R r = operateTicketService.preEdit(ticketNo);
        return r;
    }

    //以下未完成
    @PutMapping("/edittickets")
    public R editTickets(@RequestBody TicketsAddVo ticketsAddVo){
        R r = operateTicketService.editTicket(ticketsAddVo);
        return r;
    }

    //搜索框搜索
    @GetMapping("/tickettext")
    public R queryTicketText(String name,
                             @Length(min = 0, max = 2)Integer status,
                             Long startTime, Long endTime, Integer page, Integer size){
        R r = operateTicketService.textTicket(name,status, startTime, endTime, page, size);
        return r;
    }
}
